
var scale:float = 1;
var speed:float = 1;

var recalculateNormals:boolean = false;

private var baseVertices:Vector3[];
private var noise:Perlin;

function Start () {
	noise = new Perlin();
}

function Update(){
	var mesh:Mesh = GetComponent(MeshFilter).mesh;
	if(baseVertices == null){
		baseVertices = mesh.vertices;
	}
	var vertices:Vector3[] = new Vector3[baseVertices.Length];
	
	var timex = Time.time * speed ;
	var timey = Time.time * speed ;
	var timez = Time.time * speed;
	
	for(var i:int = 0;i<vertices.Length;i++){
		var vertex:Vector3 = baseVertices[i];
			vertex.x += noise.Noise(timex + vertex.x,timex + vertex.y,timex + vertex.z) * scale;
			vertex.y += noise.Noise(timey + vertex.y,timey + vertex.y,timey + vertex.z) * scale;
			vertex.z += noise.Noise(timez + vertex.z,timez + vertex.y,timez + vertex.z) * scale;
			vertices[i] = vertex;
	}
	mesh.vertices = vertices;
	
	if(recalculateNormals){
		mesh.RecalculateNormals();
	}
	mesh.RecalculateBounds();
}
